package com.ziqing.apeletnews.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.makeramen.roundedimageview.RoundedImageView;
import com.ziqing.apeletnews.R;
import com.ziqing.apeletnews.activity.EditPersonalCenterActivity;
import com.ziqing.apeletnews.activity.PersonalMessageActivtiy;
import com.ziqing.apeletnews.activity.SettingsActivtiy;
import com.ziqing.apeletnews.adapter.ToolsAdapter;
import com.ziqing.apeletnews.base.BaseFragment;
import com.ziqing.apeletnews.bean.ToolsListBean;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;

/**
 * Created by WT on 2018/4/12.
 */

public class PersonalFragment extends BaseFragment {

    @BindView(R.id.rv_tools)
    RecyclerView rvTools;
    @BindView(R.id.iv_personal_message)
    ImageView ivPersonalMessage;
    @BindView(R.id.iv_settings)
    ImageView ivSettings;
    @BindView(R.id.iv_avatar)
    RoundedImageView ivAvatar;
    @BindView(R.id.iv_edit_personal)
    RoundedImageView ivEditPersonal;
    private ToolsAdapter adapter;
    private List<ToolsListBean> data = new ArrayList<>();
    Unbinder unbinder;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_personal, container, false);
        unbinder = ButterKnife.bind(this, view);
        initView();
        rvTools.setNestedScrollingEnabled(false);
        return view;
    }

    public void initView() {

        data.add(new ToolsListBean(R.drawable.icon_lv, "LV.1"));
        data.add(new ToolsListBean(R.drawable.icon_pay, "1"));
        data.add(new ToolsListBean(R.drawable.icon_save, "收藏"));
        data.add(new ToolsListBean(R.drawable.icon_singletitle, "专题"));
        data.add(new ToolsListBean(R.drawable.icon_docement1, "文档"));
        data.add(new ToolsListBean(R.drawable.icon_book, "书签"));
        data.add(new ToolsListBean(R.drawable.icon_chat, "话题"));
        data.add(new ToolsListBean(R.drawable.icon_draft, "草稿"));

        rvTools.setLayoutManager(new GridLayoutManager(getActivity(), 5, GridLayoutManager.VERTICAL, false));
        adapter = new ToolsAdapter(getActivity(), data, R.layout.item_recycle_tools);
        rvTools.setAdapter(adapter);
        adapter.notifyDataSetChanged();
        rvTools.setFocusable(false);

    }

    @OnClick({R.id.iv_personal_message, R.id.iv_settings, R.id.iv_avatar, R.id.iv_edit_personal})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.iv_personal_message:
                startActivity(new Intent(getContext(), PersonalMessageActivtiy.class));
                break;
            case R.id.iv_settings:
                startActivity(new Intent(getContext(), SettingsActivtiy.class));
                break;
            case R.id.iv_edit_personal:
                startActivity(new Intent(getContext(), EditPersonalCenterActivity.class));
                break;
        }
    }


    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }
}
